#include "d_Math.h"
#include <iostream>

using namespace d_Math;
using namespace std;

void d_Math::gen_pascal(d_Matf& A)
{
	for(int i=0; i<A.m; i++)
		A(i,0) = 1;
	for(int i=0; i<A.n; i++)
		A(0,i) = 1;

	for(int i=1; i<A.m; i++)
		for(int j=1; j<A.n; j++)
		{
			A(i,j) = A(i-1,j)+A(i,j-1);
		}
}

void d_Math::house(d_Vecf& x, d_Vecf& v, double& b)
{
	int n = x.get_size();
	float s;

	s = x.get_part(1,x.get_size()-1)*x.get_part(1,x.get_size()-1);
	cout << "Sigma: " << s << endl;

	v[0]=1;
	v.set_part(1,x.get_part(1,x.get_size()-1));
	if(equal_to_zero(s))
		b = 0;
	else
	{
		float mu = sqrt(x[0]*x[0]+s);
		if(x[0]<=0)
			v[0]=x[0]-mu;
		else
			v[0]=-s/(x[0]+mu);
		b = (2*v[0]*v[0])/(s+v[0]*v[0]);
		v = v/v[0];
	}
}

void d_Math::QR(d_Matf& A)
{
	d_Vecf x(A.n);
	d_Vecf v(A.n);
	float b;
	for(int j=0; j<A.n; j++)
	{
		//house(
	}
}

